<template>
	<view @tap="handleC">
		<picker mode="multiSelector" @change="handleChange" @columnchange="bindMultiPickerColumnChange" :value="multiIndex" :range="multiArray">
			<view class="uni-input">{{flag?multiArray[2][multiIndex[2]]:'点击选择'}}</view>
		</picker>
	</view>
</template>
<script>
	import {apiApproverInfo} from '@/common/api.js'
	export default {
		name: "picker-c",
		data() {
			return {
				title: 'picker',
				index: 0,
				multiArray: [
					[],
					[],
					[]
				],
				aList:[],
				multiIndex: [0, 0, 0],
				flag:false
			}
		},
		created() {
			
			uni.showLoading({
				title:'初始化...',
				mask:true
			})
			apiApproverInfo().then(res=>{
				uni.hideLoading()
				this.aList = res.data.userListCheck
				this.aList.forEach((item,index)=>{
					this.multiArray[0].push(item.name)
				})
				this.aList[0].children.forEach((item,index)=>{
					this.multiArray[1].push(item.name)
					if(index == 0){
						item.children.forEach((item2,index)=>{
							this.multiArray[2].push(item2.name)
						})
					}
				})
				const result = this.aList[0].children[0].children[0]
				this.$emit('change',result)
			}).catch(err=>{
				console.log(JSON.stringify(err))
			})
			
		},
		methods: {
			bindMultiPickerColumnChange: function(e) {
				let arr1 = [],arr2 = []
				this.multiIndex[e.detail.column] = e.detail.value
				
				if(e.detail.column == 0){
					this.aList[this.multiIndex[0]].children.forEach((item,index)=>{
						arr1.push(item.name)
						if(index == this.multiIndex[1]){
							item.children.forEach((item2,index)=>{
								arr2.push(item2.name)
							})
						}
						//console.log(item)
					})
					this.multiArray[1] = arr1
					this.multiArray[2] = arr2
					
				}
				
				if(e.detail.column == 1){
					this.aList[this.multiIndex[0]].children.forEach((item,index)=>{
						if(index == e.detail.value){
							item.children.forEach((item2,index)=>{
								arr2.push(item2.name)
							})
						}
					this.multiArray[2] = arr2
					})
				}
				this.$forceUpdate()
			
			},
			handleChange(e){
				const index = e.detail.value
				const result = this.aList[index[0]].children[index[1]].children[index[2]]
				this.$emit('change',result)
			},
			handleC(){
				setTimeout(()=>{
					this.flag = true
				},100)
			},
			bindDateChange: function(e) {
				this.date = e.target.value
			},
			bindTimeChange: function(e) {
				this.time = e.target.value
			}
			
		}
	}
</script>

<style>

</style>
